unit uThreadFeature;

interface

uses
  Winapi.Windows, System.SysUtils, System.Classes, Vcl.Forms, Vcl.ComCtrls;

type
{$M+}
  TThreadFeature = class
  private
    //IsThreadActive: Boolean;
  published
    procedure ReadMaxLBA;
    procedure SetMaxLBA;
    procedure EnableWriteCache;
    procedure DisableWriteCache;
  end;
{$M-}

var
  ThreadFeature: TThreadFeature;

implementation

uses
  uFrmAction, uFrmFeature, uTaskFile;

procedure TThreadFeature.ReadMaxLBA;
var
  uLBA: UInt64;
begin
  try
    if TaskFile.ERR then
      Exit;
    FrmAction.redtHDD.Lines.Add('READ NATIVE MAX ADDRESS EXT');
    FrmAction.redtHDD.Lines.Add('--------------------------------');
    uLBA := TaskFile.ReadMaxLBA;
    if TaskFile.ERR then
    begin
      FrmAction.redtHDD.Lines.Add(' - Error' + #13#10);
      Exit;
    end
    else
      FrmAction.redtHDD.Lines.Add(' - Success' + #13#10);
    FrmFeature.edtLBA.Text := Format('%6X', [uLBA]);
  finally
  end;
end;

procedure TThreadFeature.SetMaxLBA;
var
  uLBA: UInt64;
begin
  try
    if TaskFile.ERR then
      Exit;
    FrmAction.redtHDD.Lines.Add('SET MAX ADDRESS EXT');
    FrmAction.redtHDD.Lines.Add('--------------------------------');
    uLBA := StrToUInt64('$' + FrmFeature.edtLBA.Text);
    if not TaskFile.SetMaxLBA(uLBA) then
    begin
      FrmAction.redtHDD.Lines.Add(' - Error' + #13#10);
      Exit;
    end
    else
      FrmAction.redtHDD.Lines.Add(' - Success' + #13#10);
  finally
  end;
end;

procedure TThreadFeature.EnableWriteCache;
begin
  try
    if TaskFile.ERR then
      Exit;
    FrmAction.redtHDD.Lines.Add('Enable Write Cache');
    FrmAction.redtHDD.Lines.Add('--------------------------------');
    TaskFile.ATACMD($02, $00, $00, $00, $00, TaskFile.DeviceReg, $EF);
    if TaskFile.ERR then
    begin
      FrmAction.redtHDD.Lines.Add(' - Error' + #13#10);
      Exit;
    end
    else
      FrmAction.redtHDD.Lines.Add(' - Success' + #13#10);
  finally
  end;
end;

procedure TThreadFeature.DisableWriteCache;
begin
  try
    if TaskFile.ERR then
      Exit;
    FrmAction.redtHDD.Lines.Add('Disable Write Cache');
    FrmAction.redtHDD.Lines.Add('--------------------------------');
    TaskFile.ATACMD($82, $00, $00, $00, $00, TaskFile.DeviceReg, $EF);
    if TaskFile.ERR then
    begin
      FrmAction.redtHDD.Lines.Add(' - Error' + #13#10);
      Exit;
    end
    else
      FrmAction.redtHDD.Lines.Add(' - Success' + #13#10);
  finally
  end;
end;

end.

